package com.sff.net {
	import com.sff.core.sff_internal;
	import com.sff.events.LoaderEvent;
	import com.sff.net.BaseLoaderItem;
	
	import flash.net.URLLoader;
	import flash.net.URLRequest;	
	
	use namespace sff_internal;	

	public class URLLoaderItem extends BaseLoaderItem {
		
		public var dataFormat 		: String;
		
		sff_internal var _loader 	: URLLoader;
		
		
		public function get data() : * {
			return _loader ? _loader.data : null;
		}
		
		public function URLLoaderItem( request : URLRequest, params : Object = null, statusMessage : String = null ) : void {
			super( request, context, params, statusMessage );
		}
		
		
		override public function execute() : void {
			super.execute();
			
			_loader = new URLLoader();
			if( dataFormat ) {
				_loader.dataFormat = dataFormat;
			}
			
			register( _loader );
			
			_loader.load( _request );
		}
		
		override public function dispose() : void {
			try {
				_loader.close( );
			} catch( e : Error ) {
			
			};
			
			unregister();
			dispatchEvent( new LoaderEvent( LoaderEvent.DISPOSED, this ) );
		}		
	}
}